package cn.ven.tool;

import cn.ven.entity.MyUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SessionUtil {

    public static MyUser getUser(){
        MyUser user=
                (MyUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println("MyUser="+user);
        return user;
    }


    public static int getId() {
        MyUser user = getUser();
        return user.getId();
    }


    public static String getUsername() {
        MyUser user = getUser();
        return user.getUsername();
    }


    public static String getNickname() {
        MyUser user = getUser();
        return user.getNickname();
    }


    public static String getRole() {
        MyUser user = getUser();
        return user.getRole();
    }


    public static String getPicture() {
        MyUser user = getUser();
        return user.getPicture();
    }
}
